Use extra-filename mixins to ensure that these names never clash.
}
}
- pub fn test_target(name: &str, src_path: &Path, profile: &Profile) -> Target {
+ pub fn test_target(name: &str, src_path: &Path,
+ profile: &Profile, metadata: Metadata) -> Target {
Target {
kind: BinTarget,
name: name.to_string(),
src_path: src_path.clone(),
profile: profile.clone(),
- metadata: None
+ metadata: Some(metadata),
}
}
}
}
+impl Metadata {
+ pub fn mix<T: Hash>(&mut self, t: &T) {
+ let new_metadata = short_hash(&(self.metadata.as_slice(), t));
+ self.extra_filename = format!("-{}", new_metadata);
+ self.metadata = new_metadata;
+ }
+}
+
static central_repo: &'static str = "http://rust-lang.org/central-repo";
impl Show for PackageId {
}
fn test_targets(dst: &mut Vec<Target>, tests: &[TomlTestTarget],
- default: |&TomlTestTarget| -> String) {
+ metadata: &Metadata,
+ default: |&TomlTestTarget| -> String) {
for test in tests.iter() {
let path = test.path.clone().unwrap_or_else(|| {
TomlString(default(test))
});
let profile = &Profile::default_test();
+ // make sure this metadata is different from any same-named libs.
+ let mut metadata = metadata.clone();
+ metadata.mix(&format!("test-{}", test.name.as_slice()));
+
dst.push(Target::test_target(test.name.as_slice(),
&path.to_path(),
profile,
assert_that(&p.bin("test/foo"), existing_file());
})
+test!(many_similar_names {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", "
+ pub fn foo() {}
+ #[test] fn lib_test() {}
+ ")
+ .file("src/main.rs", "
+ extern crate foo;
+ fn main() {}
+ #[test] fn bin_test() { foo::foo() }
+ ")
+ .file("tests/foo.rs", r#"
+ extern crate foo;
+ #[test] fn test_test() { foo::foo() }
+ "#);
+
+ let output = p.cargo_process("cargo-test").exec_with_output().assert();
+ let output = str::from_utf8(output.output.as_slice()).assert();
+ assert!(output.contains("test bin_test"), "bin_test missing\n{}", output);
+ assert!(output.contains("test lib_test"), "lib_test missing\n{}", output);
+ assert!(output.contains("test test_test"), "test_test missing\n{}", output);
+})
+
test!(cargo_test_failing_test {
let p = project("foo")
.file("Cargo.toml", basic_bin_manifest("foo").as_slice())